package com.potenza.training.reply.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.potenza.training.reply.entity.ReplyRecordEntity;
import com.potenza.training.reply.service.ReplyRecordService;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;



/**
 * 答辩记录
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-22 15:57:42
 */
@RestController
@RequestMapping("reply/replyrecord")
public class ReplyRecordController {
    @Autowired
    private ReplyRecordService replyRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list/{page}/{size}")
    @RequiresPermissions("reply:replyrecord:list")
    public R list(@RequestBody Map<String, Date> params,
                  @PathVariable Integer page,
                  @PathVariable Integer size){
        Page<ReplyRecordEntity> pageData = replyRecordService.queryPage(params,page,size);

        return R.ok().put("page", pageData);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("reply:replyrecord:info")
    public R info(@PathVariable("id") Long id){
		ReplyRecordEntity replyRecord = replyRecordService.getById(id);

        return R.ok().put("replyRecord", replyRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("reply:replyrecord:save")
    public R save(@RequestBody ReplyRecordEntity replyRecord){
		replyRecordService.save(replyRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("reply:replyrecord:update")
    public R update(@RequestBody ReplyRecordEntity replyRecord){
		replyRecordService.updateById(replyRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("reply:replyrecord:delete")
    public R delete(@RequestBody Long[] ids){
		replyRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 保存提交的答题记录
     * reply/replyrecord/savereply
     * @param map
     * @return
     */
    @PostMapping("/savereply")
    @RequiresPermissions("reply:replyrecord:savereply")
    public R saveReply(@RequestBody Map map){

        replyRecordService.saveReply(map);

        return R.ok();
    }

    /**
     * 根据replyId
     */
    @RequestMapping("/data/{replyId}")
    @RequiresPermissions("reply:replyrecord:data")
    public R findReplyId(@PathVariable("replyId") String replyId){
        List<ReplyRecordEntity> data = replyRecordService.findReplyId(replyId);

        return R.ok().put("data", data);
    }
}
